package org.jojo.sort;

/**
 * @author xiexiong
 */
public class InsertionSort {
    public void insertionSort(int[] nums){
        int length = nums.length;
        for(int i = 1; i< length;i++){
            for(int j = i ;j>0;j--){
                if(nums[j]<nums[j-1]){
                    swap(nums,j,j-1);
                }
            }
        }
    }

    private void swap(int[] nums, int minIndex, int i) {
        int temp;
        temp = nums[i];
        nums[i] = nums[minIndex];
        nums[minIndex] = temp;
    }
}
